﻿package {
	import game.load.PreLoadConfig;
	import game.view.AirWar;
	
	import laya.display.Sprite;
	import laya.display.Stage;
	import laya.events.Event;
	import laya.maths.Rectangle;
	import laya.ui.Label;
	import laya.utils.Handler;
	import laya.utils.Stat;
	import laya.webgl.WebGL;

	public class Main {
		
		private var _en:Sprite;
		private var _bullet:Sprite;
		private var _line:Sprite;
		private var _lbl:Label;
		private var _airWar:AirWar;
		public function Main() {
			//初始化引擎
			Laya.init(480,852,WebGL); //480,852	
			Laya.alertGlobalError = true;
			Laya.stage.bgColor= "#cccccc";
			Laya.stage.alignH = "center";
			Laya.stage.alignV = "middle";
			//Laya.stage.screenMode = Stage.SCREEN_VERTICAL
			Laya.stage.scaleMode = Stage.SCALE_SHOWALL;
			Laya.loader.load(PreLoadConfig.getConfig(),Handler.create(this,onLoad));
			Stat.show(0,0);
			
		}		
		
		private function onLoad():void
		{			
			_airWar = new AirWar();
			Laya.stage.addChild(_airWar);
		}
		
		private function onStageMove():void
		{
			var r:Rectangle = _en.getBounds();
			_bullet.pos(Laya.stage.mouseX,Laya.stage.mouseY);
			_lbl.pos(Laya.stage.mouseX,Laya.stage.mouseY);
			_line.graphics.clear();
			_line.graphics.drawLine(_en.x,_en.y+r.height,_bullet.x,_bullet.y,'#ff0000');
			
			var dx:Number = _bullet.x-_en.x;
			var dy:Number = _bullet.y-(_en.y+r.height);		
			var d:int = parseInt(""+Math.sqrt(dx*dx+dy*dy));
			_lbl.text = "距离:"+d;
		}
	}
}